home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 6 / MacMania 6.toast / / Multimedia & Desktop / sk8 / SK8InJava / Concentration / Java Code / card.java < prev    next >
Encoding:
Java Source  |  1997-02-27  |  2.2 KB  |  78 lines  |  [TEXT/SK8 ]

  1. /*  SK8 © 1997 Apple Computer, Inc.
  2.     This code is protected under the current SK8 License
  3.     See http://sk8.research.apple.com/ for more information
  4.     Apple Research Laboratories
  5. */
  6.  
  7.  
  8.  
  9. import java.awt.*;
  10.  
  11.  
  12. public class card extends rectangle {
  13.     
  14.     //----------------------------------------
  15.     //Property Definitions:
  16.     //----------------------------------------
  17.     
  18.     //The soundclip Property:
  19.     protected soundrsrc fSoundclip = null;
  20.     public soundrsrc soundclip () {
  21.         return fSoundclip;
  22.     }
  23.     public void setsoundclip (soundrsrc value) {
  24.         fSoundclip = value;
  25.     }
  26.     
  27.     
  28.     //----------------------------------------
  29.     //Handler Definitions:
  30.     //----------------------------------------
  31.     
  32.     //Initialization function
  33.     public card() {
  34.         super();
  35.         this.setsize(sk8.list(30, 30));
  36.     }
  37.     /*   add 1 to the score of the current player.
  38.     color clicked cards diablo and hide them.
  39.     check if the game has ended.
  40.     */
  41.     public Object click (  ) {
  42.         player goodplayer;
  43.         if ((this.fillcolor() != sk8.red)) { 
  44.             if ((sk8concentration.currentclickedcard == null)) { 
  45.                 this.soundclip().play();
  46.                 this.setfillcolor(sk8.red);
  47.                 sk8concentration.currentclickedcard = this;
  48.             } else { 
  49.                 this.soundclip().play();
  50.                 this.setfillcolor(sk8.red);
  51.                 if ((((card)sk8concentration.currentclickedcard).soundclip() == this.soundclip())) { 
  52.                     goodplayer = (player) sk8concentration.board.currentplayer();
  53.                     goodplayer.setscore((1 + goodplayer.score()));
  54.                     this.setfillcolor(sk8concentration.diablo);
  55.                     this.hide();
  56.                     sk8concentration.currentclickedcard.setfillcolor(sk8concentration.diablo);
  57.                     sk8concentration.currentclickedcard.hide();
  58.                     if ((sk8concentration.player1.score() + sk8concentration.player2.score()) >= 8) { 
  59.                         sk8.messagetouser("Game Over");
  60.                     }
  61.                 } else { 
  62.                     this.setfillcolor(sk8concentration.diablo);
  63.                     sk8concentration.currentclickedcard.setfillcolor(sk8concentration.diablo);
  64.                     if ((sk8concentration.board.currentplayer() == sk8concentration.player1)) { 
  65.                         sk8concentration.board.setcurrentplayer(sk8concentration.player2);
  66.                     } else { 
  67.                         sk8concentration.board.setcurrentplayer(sk8concentration.player1);
  68.                     }
  69.                 }
  70.                 sk8concentration.currentclickedcard = null;
  71.             }
  72.         }
  73.         return null;
  74.     }
  75.     
  76.     
  77. }
  78.